<template>
	<view>
		<view>
			<u-tabs-swiper ref="uTabs" :list="list" :current="current" @change='tabsChange' :is-scroll="false"
			 swiperWidth="750"></u-tabs-swiper>
		</view>
		<swiper :current="swiperCurrent" @transition="transition" @animationfinish='animationfinish'>
			<swiper-item class="swiper-item" v-for="(item, index) in tabs" :key="index">
				<scroll-view scroll-y style="height: 800rpx;width: 100%;" @scrolltolower='onreachBottom'>
								
					<view class='list pad30' v-if='seckillList.length>0' style="margin-top:12px;">
							<block v-for="(item,index) in seckillList" :key='index'>
								<view class='item acea-row row-between-wrapper' @tap='goDetails(item)'>
									<view class='pictrue'>
										<image :src='item.image'></image>
									</view>
									<view class='text acea-row row-column-around'>
										<view class='name line1'>{{item.title}}</view>
										<view class='money'><text class="font-color">￥</text>
											<text class='num font-color'>{{item.price}}</text>
											<text class="y_money">￥{{item.otPrice}}</text>
										</view>
										<view class="limit">限量 <text class="limitPrice">{{item.quota}} {{item.unitName}}</text>
										</view>
										<view class="progress">
											<view class='bg-reds' :style="'width:'+item.percent+'%;'"></view>
											<view class='piece'>已抢{{item.percent}}%</view>
										</view>
									</view>
									<view class='grab bg-color' v-if="status == 2">马上抢</view>
									<view class='grab bg-color' v-else-if="status == 1">未开始</view>
									<view class='grab bg-color-hui' v-else>已结束</view>
								</view>
							</block>
						</view>
					
					
					
					<!-- <view class='noCommodity' v-if="seckillList.length == 0 && (page != 1 || active== 0)">
						<view class='pictrue'>
							<image src='../../../static/images/noShopper.png'></image>
						</view>
					</view> -->
					<home></home>
				
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		getSeckillHeaderApi,
		getSeckillList
	} from '../../../api/activity.js';
	import home from '@/components/home/index.vue';
	let app = getApp();
	export default {
		components: {
			home
		},
		data() {
			return {
				list: [{
					name: '早场秒杀'
				}, {
					name: '中午场秒杀'
				}, {
					name: '下午场秒杀'
				},{
					name: '晚间秒杀'
				}],
				tabs: [{
					name: '十年'
				}, {
					name: '青春'
				}, {
					name: '之约'
				}],
				// 因为内部的滑动机制限制，请将tabs组件和swiper组件的current用不同变量赋值
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
				circular: true,
				autoplay: true,
				interval: 500,
				topImage: '',
				seckillList: [],
				timeList: [],
				active: 0,
				scrollLeft: 0,
				interval: 0,
				status: 1,
				countDownHour: "00",
				countDownMinute: "00",
				countDownSecond: "00",
				page: 1,
				limit: 4,
				loading: false,
				loadend: false,
				pageloading: false,
				dataList: [],
				returnShow: true,
				navH: '',
			};
		},
		onLoad() {
		
			this.getSeckillList();
		},
		
		methods: {
			// tabs通知swiper切换
			tabsChange(index) {
				let that = this;
				that.swiperCurrent = index;
				that.getSeckillList();
				console.log(that.swiperCurrent,'this.swiperCurrent',that.current);
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.uTabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.uTabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.current = current;
			},
			// scroll-view到底部加载更多
			onreachBottom() {
				
			},
			getSeckillConfig: function() {
				let that = this;
				getSeckillHeaderApi().then(res => {
					res.data.map(item => {
						item.slide = JSON.parse(item.slide)
					})
					that.dataList = res.data;
					that.getSeckillList();
					that.seckillList = [];
					that.page = 1;
					that.status = that.dataList[that.active].status;
					that.getSeckillList();
			
				});
			},
			getSeckillList: function() {
				var that = this;
				var data = {
					page: that.page,
					limit: that.limit					
				};
				// let timeId = 
				// if (that.loadend) return;
				// if (that.pageloading) return;
				this.pageloading = true
				let num = that.swiperCurrent+1
				 getSeckillList(num, data).then(res => {
					console.log('555');
					var seckillList = res.data.list;
					var loadend = seckillList.length < that.limit;
					that.page++;
					that.seckillList = that.seckillList.concat(seckillList),
						that.page = that.page;
					// that.pageloading = false;
					// that.loadend = loadend;
					console.log('1223',res.data.list);
					
				}).catch(err => {
					that.pageloading = false
					
					console.log('123');
				});
			},
			settimeList: function(item, index) {
				var that = this;
				this.active = index
				if (that.interval) {
					clearInterval(that.interval);
					that.interval = null
				}
				that.interval = 0,
					that.countDownHour = "00";
				that.countDownMinute = "00";
				that.countDownSecond = "00";
				that.status = that.dataList[that.active].status;
				that.loadend = false;
				that.page = 1;
				that.seckillList = [];
				// wxh.time(e.currentTarget.dataset.stop, that);
				that.getSeckillList();
			},
		}
	};
</script>